;solution for euler 31

(defun solve-euler31 ()
	(let ((coins (vector 1 2 5 10 20 50 100 200))
			(cur (vector 200))
			left start
			(count 1))
		(sort coins #'>)
		(loop
			(sort cur #'<)
			(print cur)
			(when (= count 5) (return))
			(when (= (elt cur (- (length cur) 1)) 1) (return))
			(setf start 0)
			(loop 
				(setf left (elt cur start))
				(incf start)
				(when (/= 1 left) (return)))
			(setf cur (remove left cur :count 1 :from-end t))
			(setf start left)

			(loop
				(dotimes (i (length coins))
					(when (and (<= (elt coins i) left) (/= (elt coins i) start))
						(decf left (elt coins i))
						(setf cur (concatenate 'vector cur (vector (elt coins i))))
						(return)))
				(when (= left 0) (return)))
			(incf count))
		(format t "Euler 31:~a" count)))
		